package com.ocom.human.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.human.EntityPageEnum;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.utils.StringUtils;
import com.ocom.human.dao.IDaoPageEnum;
import com.ocom.human.service.PageEnumService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class PageEnumServiceImpl extends ServiceImpl<IDaoPageEnum, EntityPageEnum> implements PageEnumService {

    @Autowired
    private IDaoPageEnum iDaoPageEnum;

    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityPageEnum> selectPageEnum() {
        QueryWrapper<EntityPageEnum> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("type","systemRole");
        queryWrapper.orderByAsc("tip");
        return iDaoPageEnum.selectList(queryWrapper);
    }

    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityPageEnum> getXfVerList() {
        QueryWrapper<EntityPageEnum> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("type","xfVer");
        queryWrapper.orderByAsc("sort");
        return iDaoPageEnum.selectList(queryWrapper);
    }

    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityPageEnum> getMjVerList() {
        QueryWrapper<EntityPageEnum> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("type","mjVer");
        queryWrapper.orderByAsc("sort");
        return iDaoPageEnum.selectList(queryWrapper);
    }


    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityPageEnum> getPageEnumByType( @RequestParam("type") String type) {
        QueryWrapper<EntityPageEnum> queryWrapper=new QueryWrapper<>();
        if (StringUtils.isNotEmpty(type)){
            queryWrapper.eq("type",type);
        }
        queryWrapper.orderByAsc(" type,sort");
        return iDaoPageEnum.selectList(queryWrapper);
    }
}
